<%-- 
    Document   : addCart
    Created on : Dec 27, 2013, 3:40:27 AM
    Author     : Welcome
--%>

<%@page import="businesscard.DAO.UserDAO"%>
<%@page import="bc.entity.User"%>
<%@page import="businesscard.DAO.GiohangDAO"%>
<%@page import="bc.entity.Giohang"%>
<%@page import="bc.entity.Lienhe"%>
<%@page import="businesscard.DAO.LienheDAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
    int id = Integer.parseInt(request.getParameter("id"));
    LienheDAO lhDAO = new LienheDAO();
    Lienhe lh = lhDAO.getLienHe1(id);
    GiohangDAO ghDAO = new GiohangDAO();
    HttpSession session3 = request.getSession();
    User user3 = (User) session3.getAttribute("USER");
    String username = user3.getUser();
    UserDAO userDAO = new UserDAO();
    User user4 = userDAO.getUser2(username);
    int id_user2 = user4.getIdUser();
    int count = ghDAO.countLH(id_user2);
    int tien = lh.getCapbac().getDongia();
 Giohang[] gh1 = ghDAO.getAllGiohang(id_user2);
 if (gh1.length == 0) {
        count = count + 1;
        Giohang gh = new Giohang(user4, lh, tien);
        ghDAO.Save(gh);
    } else {
        for (int i = 0; i < gh1.length; i++) {
            int id_lienhe = gh1[i].getLienhe().getIdLienhe();
            if (id != id_lienhe) {
                count = count + 1;
                Giohang gh = new Giohang(user4, lh, tien);
                ghDAO.Save(gh);
            } 
        }
    }
        out.print(count);
%>

